﻿using Database.ERPNext;
using DataViews.ViewModels;
using Main.Configs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main.ViewModels
{
    public class GloabalViewModel
    {
        static FilterListViewModel<tabGL_Entry>? _GLEntry_FilterListViewModel = null;
        public static FilterListViewModel<tabGL_Entry>? GLEntry_FilterListViewModel
        {
            get
            {
                if (_GLEntry_FilterListViewModel == null)
                {
                    _GLEntry_FilterListViewModel = new FilterListViewModel<Database.ERPNext.tabGL_Entry>("GLEntry", VoucherPrintConfig.Current.Filters);
                }
                return _GLEntry_FilterListViewModel;
            }
        }

        static DataListViewModel<tabGL_Entry>? _GLEntry_DataListViewModel = null;
        public static DataListViewModel<tabGL_Entry>? GLEntry_DataListViewModel
        { 
            get{                
                if(_GLEntry_DataListViewModel == null)
                {
                    try
                    {
                        _GLEntry_DataListViewModel = new DataListViewModel<tabGL_Entry>("GLEntry", VoucherPrintConfig.Current.DisplayFields,
                                Database.ERPNext.ERPNextDbContext.Current.tabGL_Entries.Where(x => x.is_cancelled == 0)
                                , VoucherPrintConfig.Current.DisplayCountPerPage);
                    }
                    catch(Exception ex)
                    {
                        Serilog.Log.Error($"【数据】发生GL_Entry数据时发生错误：{ex.Message}");
                    }
                   
                }
                return _GLEntry_DataListViewModel;
            } 
        }
    }
}
